package com.splic.web.controller.product;

import java.util.List;
import com.splic.common.utils.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.splic.common.annotation.Log;
import com.splic.common.enums.BusinessType;
import com.splic.product.domain.UserBloodsugarData;
import com.splic.product.service.UserBloodsugarDataService;
import com.splic.common.core.controller.BaseController;
import com.splic.common.core.domain.AjaxResult;
import com.splic.common.utils.poi.ExcelUtil;
import com.splic.common.core.page.TableDataInfo;

/**
 * 用户血糖数据Controller
 * 
 * @author singe
 * @date 2022-01-04
 */
@Controller
@RequestMapping("/product/userBloodsugarData")
public class UserBloodsugarDataController extends BaseController
{
    private String prefix = "product/userBloodsugarData";

    @Autowired
    private UserBloodsugarDataService userBloodsugarDataServiceImpl;

    @RequiresPermissions("product:userBloodsugarData:view")
    @GetMapping()
    public String userBloodsugarData()
    {
        return prefix + "/list";
    }

    /**
     * 查询用户血糖数据列表
     */
    @RequiresPermissions("product:userBloodsugarData:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UserBloodsugarData userBloodsugarData)
    {
        startPage();
        List<UserBloodsugarData> list = userBloodsugarDataServiceImpl.selectUserBloodsugarDataList(userBloodsugarData);
        return getDataTable(list);
    }

    /**
     * 新增用户血糖数据
     */
    @GetMapping(value = { "/form/{id}", "/form" })
    public String form(@PathVariable(value = "id", required = false) Long id, ModelMap mmap)
    {
        if (StringUtils.isNotNull(id)){
            mmap.put("userBloodsugarData", userBloodsugarDataServiceImpl.selectUserBloodsugarDataById(id));
        }else{
            mmap.put("userBloodsugarData", new UserBloodsugarData());
        }
        return prefix + "/form";
    }


    /**
     * 新增保存用户血糖数据
     */
    @RequiresPermissions("product:userBloodsugarData:edit")
    @Log(title = "用户血糖数据", businessType = BusinessType.INSERT)
    @PostMapping("/saveOrUpdate")
    @ResponseBody
    public AjaxResult saveOrUpdate(UserBloodsugarData userBloodsugarData)
    {
        return toAjax(userBloodsugarDataServiceImpl.saveOrUpdate(userBloodsugarData));
    }

    /**
     * 删除
     */
    @RequiresPermissions("product:userBloodsugarData:remove")
    @Log(title = "用户血糖数据", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(Long id)
    {
        return toAjax(userBloodsugarDataServiceImpl.deleteById(id));
    }


    /**
     * 导出用户血糖数据列表
     */
    @RequiresPermissions("product:userBloodsugarData:export")
    @Log(title = "用户血糖数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UserBloodsugarData userBloodsugarData)
    {
        List<UserBloodsugarData> list = userBloodsugarDataServiceImpl.selectUserBloodsugarDataList(userBloodsugarData);
        ExcelUtil<UserBloodsugarData> util = new ExcelUtil<UserBloodsugarData>(UserBloodsugarData.class);
        return util.exportExcel(list, "用户血糖数据数据");
    }

}
